package com.sz.common.base.utils;

import java.util.Collection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Function:  StringUtils <br>
 * Author: wentao.chang <br>
 * Date: 2017-01-04 09:50:00
 */
public class StringUtils extends org.springframework.util.StringUtils {


    public static final String NUMBER_REGEX = "-?[0-9]*";

    /**
     * 替换查询字段的通配符
     *
     * @param str
     * @return
     */
    public static String replaceSqlPattern(String str) {
        if (str == null || str.length() == 0) {
            return str;
        }
        str = str.replaceAll("\\\\", "\\\\\\\\");
        str = str.replaceAll("_", "\\\\_");
        str = str.replaceAll("%", "\\\\%");
        return str.trim();
    }

    public static boolean isNumber(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }
        Pattern pattern = Pattern.compile(NUMBER_REGEX);
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }

    public static boolean isNotEmpty(String str) {
        return ! StringUtils.isEmpty(str);
    }

    public static String toCommaString(Collection<String> strs){
        return collectionToCommaDelimitedString(strs);
    }
}
